
module.exports = app => {

    return class LoginController extends app.Controller {

        async login() {
            let method = this.ctx.request.method;
            if ("GET" == method){
                let authorization = await this.ctx.service.authorization.authorization();
                await this.ctx.render('login/index.js', {
                    authorization
                });
            }else{
                let params = this.ctx.request.body;

                let mobile = params.mobile;
                let code = params.code;

                let data = await this.ctx.service.login.login({
                    mobile,
                    code
                });

                //将用户登录成功信息放入sesison中
                this.ctx.session.member = data;

                this.success(data);
            }
        }

    };
};
